﻿package mortal.game.view.copy.defenseCopy
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import flash.utils.*;
    import mortal.game.cache.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.copy.groupCopy.data.*;
    import mortal.game.view.copy.groupCopy.view.*;

    public class DefenseCopyUtil extends Object
    {
        public static const MAX_COMPOSE_MATERIAL:int = 4;
        public static const BG_LEN:int = 44;
        public static const LINE_H:int = 25;
        public static const singleDefenseCode:int = 112;
        public static const singleDefenseGuideCode:int = 128;
        public static const groupDefenseCode:int = 138;

        public function DefenseCopyUtil()
        {
            return;
        }// end function

        public static function get isEquipTab() : Boolean
        {
            return Cache.instance.copy.defenseCopy.curTab == 1;
        }// end function

        public static function getPriceByCode(param1:int) : int
        {
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            var _loc_6:TDefenseCopyShopSell = null;
            var _loc_7:Dictionary = null;
            var _loc_8:int = 0;
            var _loc_9:int = 0;
            var _loc_10:int = 0;
            var _loc_11:int = 0;
            var _loc_2:* = DefenseCopyComposeConfig.instance.getConfigByItemCode(param1);
            if (_loc_2 == null)
            {
                _loc_6 = DefenseCopyShopConfig.instance.getItem(1, param1);
                if (_loc_6 == null)
                {
                    return 0;
                }
                _loc_5 = _loc_5 + _loc_6.buyValue;
            }
            else
            {
                _loc_7 = new Dictionary();
                _loc_5 = _loc_5 + _loc_2.equipPoint;
                _loc_8 = 1;
                while (_loc_8 <= MAX_COMPOSE_MATERIAL)
                {
                    
                    _loc_3 = _loc_2["material" + _loc_8] as int;
                    _loc_4 = _loc_2["num" + _loc_8] as int;
                    _loc_9 = getItemNum(_loc_3);
                    _loc_10 = int(_loc_7[_loc_3]);
                    _loc_11 = _loc_9 - _loc_10;
                    if (_loc_3 > 0 && _loc_11 < _loc_4)
                    {
                        _loc_6 = DefenseCopyShopConfig.instance.getItem(1, _loc_3);
                        if (_loc_6 == null)
                        {
                            _loc_5 = _loc_5 + 0;
                        }
                        else
                        {
                            _loc_5 = _loc_5 + int(_loc_6.buyValue) * (_loc_4 - _loc_11);
                        }
                        _loc_7[_loc_3] = int(_loc_7[_loc_3]) + _loc_11;
                    }
                    else
                    {
                        _loc_7[_loc_3] = int(_loc_7[_loc_3]) + _loc_4;
                    }
                    _loc_8++;
                }
            }
            return _loc_5;
        }// end function

        public static function getItemNum(param1:int) : int
        {
            var judge:Function;
            var itemCode:* = param1;
            judge = function (param1:ItemData) : Boolean
            {
                return param1.itemCode == itemCode;
            }// end function
            ;
            var bagItemNum:* = Cache.instance.pack.defenseBag.getItemCountByJudge(judge);
            var roleItemNum:* = Cache.instance.pack.defenseRoleEquipCache.getItemCountByJudge(judge);
            return bagItemNum + roleItemNum;
        }// end function

        public static function getIsEnoughGem(param1:int) : Boolean
        {
            var _loc_3:int = 0;
            return true;
            return true;
        }// end function

        public static function getMaxLenByLayer(param1:int) : int
        {
            return Cache.instance.copy.defenseCopy.maxLenght;
        }// end function

        public static function get scale() : Number
        {
            var _loc_1:* = Cache.instance.copy.defenseCopy.maxLayer;
            if (_loc_1 == 1)
            {
                return 1;
            }
            if (_loc_1 == 2)
            {
                return 0.85;
            }
            if (_loc_1 == 3)
            {
                return 0.55;
            }
            return 0.4;
        }// end function

        public static function setMaxLenght() : void
        {
            var _loc_1:* = Cache.instance.copy.defenseCopy;
            if (_loc_1.maxLayer == 1)
            {
                _loc_1.maxLenght = 200;
            }
            else if (_loc_1.maxLayer == 2)
            {
                _loc_1.maxLenght = 260;
            }
            else if (_loc_1.maxLayer == 3)
            {
                _loc_1.maxLenght = 320;
            }
            else if (_loc_1.maxLayer == 4)
            {
                _loc_1.maxLenght = 360;
            }
            return;
        }// end function

        public static function isInTeamDefenseCopy() : Boolean
        {
            if (Cache.instance.copy.copyInfo == null)
            {
                return false;
            }
            if (GroupCopyGroupDefensePanel.GroupDefenCopyId == Cache.instance.copy.copyInfo.code)
            {
                return true;
            }
            return false;
        }// end function

        public static function isShowOrangeEquip() : Boolean
        {
            if (Cache.instance.copy.copyInfo == null)
            {
                return false;
            }
            if (DefenseInfo.OrangeEquipCopyCode == Cache.instance.copy.copyInfo.code)
            {
                return true;
            }
            return false;
        }// end function

        public static function isInSingleDefenseCopy() : Boolean
        {
            if (Cache.instance.copy.copyInfo.group == 112)
            {
                return true;
            }
            return false;
        }// end function

        public static function isInDefenseCopy() : Boolean
        {
            if (Cache.instance.copy.copyInfo == null)
            {
                return false;
            }
            if (Cache.instance.copy.copyInfo.group == 112 || Cache.instance.copy.copyInfo.group == 128 || Cache.instance.copy.copyInfo.group == 138)
            {
                return true;
            }
            return false;
        }// end function

        public static function getPassInfoArr() : Array
        {
            var _loc_5:SDefenseCopyReward = null;
            var _loc_6:String = null;
            var _loc_7:int = 0;
            var _loc_8:ItemData = null;
            var _loc_1:Array = [];
            var _loc_2:Array = [0, 0];
            _loc_2[0] = Cache.instance.copy.defenseCopy.boNum;
            _loc_2[1] = Cache.instance.copy.defenseCopy.totalBoNum;
            _loc_1.push(_loc_2);
            var _loc_3:Array = [];
            var _loc_4:* = Cache.instance.copy.defenseCopy.resultInfo;
            if (_loc_4)
            {
                _loc_5 = _loc_4.reward;
                for (_loc_6 in _loc_5.rewards)
                {
                    
                    _loc_7 = int(_loc_6);
                    _loc_8 = new ItemData(_loc_7);
                    _loc_8.itemAmount = int(_loc_5.rewards[_loc_6]);
                    _loc_3.push(_loc_8);
                }
            }
            _loc_1.push(_loc_3);
            return _loc_1;
        }// end function

    }
}
